package com.ruoyi.wcf.controller;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wcf.domain.WcfMobileSeries;
import com.ruoyi.wcf.service.IWcfMobileSeriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手机系列Controller
 *
 * @author WZP
 * @date 2022-04-02
 */
@RestController
@RequestMapping("/wcf/WcfMobileSeries")
public class WcfMobileSeriesController extends BaseController
{
    @Autowired
    private IWcfMobileSeriesService wcfMobileSeriesService;

    /**
     * 查询手机系列列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:list')")
    @GetMapping("/list")
    public TableDataInfo list(WcfMobileSeries wcfMobileSeries)
    {
        startPage();
        List<WcfMobileSeries> list = wcfMobileSeriesService.selectWcfMobileSeriesList(wcfMobileSeries);
        return getDataTable(list);
    }

    /**
     * 导出手机系列列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:export')")
    @Log(title = "手机系列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WcfMobileSeries wcfMobileSeries)
    {
        List<WcfMobileSeries> list = wcfMobileSeriesService.selectWcfMobileSeriesList(wcfMobileSeries);
        ExcelUtil<WcfMobileSeries> util = new ExcelUtil<WcfMobileSeries>(WcfMobileSeries.class);
        return util.exportExcel(list, "手机系列数据");
    }

    /**
     * 获取手机系列详细信息
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:query')")
    @GetMapping(value = "/{seriesId}")
    public AjaxResult getInfo(@PathVariable("seriesId") Long seriesId)
    {
        return AjaxResult.success(wcfMobileSeriesService.selectWcfMobileSeriesBySeriesId(seriesId));
    }

    /**
     * 新增手机系列
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:add')")
    @Log(title = "手机系列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WcfMobileSeries wcfMobileSeries)
    {
        return toAjax(wcfMobileSeriesService.insertWcfMobileSeries(wcfMobileSeries));
    }

    /**
     * 修改手机系列
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:edit')")
    @Log(title = "手机系列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WcfMobileSeries wcfMobileSeries)
    {
        return toAjax(wcfMobileSeriesService.updateWcfMobileSeries(wcfMobileSeries));
    }

    /**
     * 删除手机系列
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileSeries:remove')")
    @Log(title = "手机系列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seriesIds}")
    public AjaxResult remove(@PathVariable Long[] seriesIds)
    {
        return toAjax(wcfMobileSeriesService.deleteWcfMobileSeriesBySeriesIds(seriesIds));
    }

    /**
     * 手机系列下拉列表
     * @param map
     * @return
     */
    @GetMapping("/getSelectList")
    public AjaxResult getSelectList(@RequestParam Map<String,Object> map){
        if (!map.containsKey("brandId")){
            return AjaxResult.error("缺少参数");
        }

        return AjaxResult.success(wcfMobileSeriesService.getSelectList(map));
    }
}
